package com.myproject.proxy.javasist;

import com.myproject.proxy.cglib.Teacher;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;

public class JavasistTest {

    public static void main(String[] args) throws Exception{

        ClassPool pool = ClassPool.getDefault();
        //创建Programmer类
        CtClass cc= pool.makeClass("com.samples.Programmer");
        //定义code方法
        CtMethod method = CtNewMethod.make("public void code(){}", cc);
        //插入方法代码
        method.insertBefore("System.out.println(\"I'm a Programmer,Just Coding.....\");");
        cc.addMethod(method);
        Class c = cc.toClass();
        System.out.println(c.getClassLoader());
        System.out.println(c);
        System.out.println(Teacher.class);
        System.out.println(new Object());
        //保存生成的字节码
        //cc.writeFile("d://temp");

    }

}
